package com.example.demo.controller;

import com.example.demo.mapper.OrgMapper;
import com.example.demo.service.InsertData;
import com.example.demo.util.LoginAndToken;
import org.apache.hc.core5.http.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;

//往数据库里面插入数据
@Controller
public class GetDataController {

    @Autowired
    InsertData insertData;

    @Autowired
    OrgMapper orgMapper;

    @GetMapping("/dieChicken")
    @ResponseBody
    public String insertData(@RequestParam String date,
                             @RequestParam String name,
                             @RequestParam(required = false) String isAudit,
                             @RequestParam(required = false) String isSend) throws URISyntaxException, IOException, ParseException {
//        Map orgIdByName = LoginAndToken.getOrgIdByName(orgName);
        Integer orgId = orgMapper.getOrgIdByOrgName(name);


        int i = insertData.insertDieChicken(date,name,isAudit,isSend,orgId);
        return "插入成功数据：" + i + "条";
    }

}
